//
//  CZEmoticonTipView.swift
//  新浪微博
//
//  Created by 名品导购网MPLife.com on 2017/12/20.
//  Copyright © 2017年 sweet. All rights reserved.
//

import UIKit
import pop
//表情选择提示视图
class CZEmoticonTipView: UIImageView {
    
    private var preEmoticon:CZEmoticon?
    //私有控件
    private lazy var tipButton = UIButton()
    var emoticon:CZEmoticon? {
        didSet{
            if emoticon == preEmoticon {
                return
            }
            preEmoticon = emoticon
            tipButton.setTitle(emoticon?.emoji, for: .normal)
            tipButton.setImage(emoticon?.image, for: .normal)
            //设置动画-弹力动画的结束时间 根据速度自动计算的 不需要也不能指定
            let anim:POPSpringAnimation = POPSpringAnimation(propertyNamed: kPOPLayerPositionY)
            anim.fromValue = 30
            anim.toValue = 8
            anim.springBounciness = 15
            anim.springSpeed = 15
            tipButton.layer.pop_add(anim, forKey: nil)
    }
}
    //构造函数
    init() {
        let bundle = CZEmoticonManager.shared.bundle
        let image = UIImage(named: "emoticon_keyboard_magnifier", in: bundle, compatibleWith: nil)
        //uiimageview alloc initwithImage 会更具图像大小 设置图像视图的大小
        super.init(image: image)
        //设置牟点
        layer.anchorPoint = CGPoint(x: 0.5, y: 1.2)
        //添加按钮
        tipButton.layer.anchorPoint = CGPoint(x: 0.5, y: 0)
        tipButton.frame = CGRect(x: 0, y: 8, width: 36, height: 36)
        tipButton.center.x = bounds.width * 0.5
        tipButton .setTitle("😀", for: .normal)
        tipButton.titleLabel?.font = UIFont.systemFont(ofSize: 32)
        addSubview(tipButton)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}








